package com.sansecy.customview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

public class TextTest extends View {
    public TextTest(Context context) {
        super(context);
    }

    public TextTest(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        paint.setTextSize(124);
        paint.setStrokeWidth(5);
        int textHeight = PaintUtil.getTextHeight(0, paint);
        int textWidth = PaintUtil.getTextWidth("0", paint);
        int baseLineY = PaintUtil.getNoPaddingBaseLineY(0, paint);
        canvas.drawText("0今天", 0, 400+100, paint);
        Rect rect = new Rect();
        paint.getTextBounds("0", 0, 1, rect);
        canvas.drawLine(0, 400+rect.bottom+100, 1000, 400+rect.bottom+100, paint);
        canvas.drawLine(0, 400+rect.top+100, 1000, 400+rect.top+100, paint);
        canvas.drawLine(rect.left, 400+rect.top+100, rect.left, 400+rect.bottom+100, paint);
        canvas.drawLine(rect.right, 400+rect.top+100, rect.right, 400+rect.bottom+100, paint);
        Paint.FontMetricsInt fontMetricsInt = paint.getFontMetricsInt();
        int i = Math.abs(fontMetricsInt.top) - Math.abs(fontMetricsInt.ascent);
//        canvas.drawLine(0, i+100, 1000, i+100, paint);
//        canvas.drawLine(0, 400+fontMetricsInt.top+100, 1000, 400+fontMetricsInt.top+100, paint);
//        canvas.drawLine(0, 400+fontMetricsInt.ascent+100, 1000, 400+fontMetricsInt.ascent+100, paint);
//        canvas.drawLine(0, 400+100, 1000, 400+100, paint);
//        canvas.drawLine(0, 400+fontMetricsInt.descent+100, 1000, 400+fontMetricsInt.descent+100, paint);
//        canvas.drawLine(0, 400+fontMetricsInt.bottom+100, 1000, 400+fontMetricsInt.bottom+100, paint);

    }

}
